#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Testes unitários da classe Table2CSV
# Versão 0.2

import unittest
from libtable2csv import Table2CSV

class TestTable2CSV(unittest.TestCase):

    VALID_HTML_TABLE = """
<html>
 <body>
  <table>
   <tr><th>Título A</th><th>Título B</th></tr>
   <tr><td>Valor Texto</td><td>1000</td></tr>
   <tr><td>1.45</td><td>85%</td></tr>
  </table>
 </body>
</html>"""

    def testTable2CSVInstance(self):
        t2csv = Table2CSV()
        self.assertIsInstance(t2csv, Table2CSV)

    def testRead(self):
        t2csv = Table2CSV()
        self.assertGreater(t2csv.read(self.VALID_HTML_TABLE), 0)

    def testWrite(self):
        t2csv = Table2CSV()
        t2csv.read(self.VALID_HTML_TABLE)
        self.assertIsInstance(t2csv.convert(), file)

    def testConvert(self):
        t2csv = Table2CSV()
        t2csv.read(self.VALID_HTML_TABLE)
        self.assertEqual(
            t2csv.convert().readlines(),
            ['"Título A","Título B"\r\n',
             '"Valor Texto","1000"\r\n',
             '"1.45","85%"\r\n'])

if __name__=="__main__":
    unittest.main()
